<template>
  <div class="history-display-container">
    <h3 class="history-title">最近抽取历史</h3>
    <div class="history-list">
      <div v-if="history.length === 0" class="no-history">
        <p>暂无抽取历史</p>
      </div>
      <div 
        v-for="(item, index) in history"
        :key="index"
        class="history-item"
        :class="{ 'latest': index === 0 }"
      >
        <div class="history-index">{{ index + 1 }}</div>
        <div class="history-content">
          <div class="history-food-name">{{ item.name }}</div>
          <div class="history-meta">
            <span class="history-category">{{ getCategoryName(item.category) }}</span>
            <span class="history-time">{{ formatTime(item.timestamp) }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HistoryDisplay',
  props: {
    history: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    getCategoryName(category) {
      const categoryMap = {
        'chinese': '中餐',
        'western': '西餐',
        'japanese': '日料',
        'korean': '韩餐',
        'fastfood': '快餐',
        'snack': '小吃',
        'dessert': '甜品',
        'drink': '饮品'
      };
      return categoryMap[category] || category;
    },
    formatTime(timestamp) {
      const date = new Date(timestamp);
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      const seconds = date.getSeconds().toString().padStart(2, '0');
      return `${hours}:${minutes}:${seconds}`;
    }
  }
}
</script>

<style scoped>
.history-display-container {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.history-title {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.no-history {
  text-align: center;
  padding: 30px 0;
  color: #999;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: #e9ecef;
  transform: translateX(4px);
}

.history-item.latest {
  background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
  border: 1px solid #ffeeba;
}

.history-item.latest:hover {
  background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 100%);
}

.history-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: #dee2e6;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  color: #495057;
  flex-shrink: 0;
}

.history-item.latest .history-index {
  background: #ffc107;
  color: #212529;
}

.history-content {
  flex: 1;
  min-width: 0;
}

.history-food-name {
  font-weight: 500;
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-category {
  font-size: 12px;
  padding: 2px 8px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  color: #666;
}

.history-time {
  font-size: 11px;
  color: #999;
}

.history-item.latest .history-food-name {
  color: #856404;
}

.history-item.latest .history-category {
  background: rgba(255, 193, 7, 0.2);
  color: #856404;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .history-display-container {
    padding: 16px;
  }
  
  .history-title {
    font-size: 15px;
    margin-bottom: 12px;
  }
  
  .history-item {
    padding: 10px;
    gap: 10px;
  }
  
  .history-food-name {
    font-size: 13px;
  }
  
  .history-category {
    font-size: 11px;
    padding: 1px 6px;
  }
  
  .history-time {
    font-size: 10px;
  }
}

@media (max-width: 480px) {
  .history-display-container {
    padding: 14px;
  }
  
  .history-title {
    font-size: 14px;
  }
  
  .history-item {
    padding: 8px;
    gap: 8px;
  }
  
  .history-index {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }
  
  .history-food-name {
    font-size: 12px;
  }
}
</style>